/*****************************************************************************************
 * FILE NAME: mock_crc.c                                COPYRIGHT (c) TX 2025
 * REVISION:  1.0.0                                     All Rights Reserved
 * DESCRIPTION: 模拟CRC校验函数
 * =======================================================================================
 * UPDATE HISTORY：
 * REV      AUTHOR      DATE
 * v1.0.0   fangangchuan  2025.10.15
 * DESCRIPTION OF CHANGE: 为单元测试提供模拟的CRC校验函数
 ****************************************************************************************/

//----------------------------------------------------------------------------------------
// @Project Includes
#include "test_chaodian_can_L.h"

//----------------------------------------------------------------------------------------
// @Local Macro Define in the module

//----------------------------------------------------------------------------------------
// @Local Type defines in the module

//----------------------------------------------------------------------------------------
// @Global Variables define in the module

//----------------------------------------------------------------------------------------
// @Local Variables

//----------------------------------------------------------------------------------------
// 模拟函数实现
//----------------------------------------------------------------------------------------

/*
 * @Functions:   uint16_t srv_crc16_system(const uint8_t* data, uint16_t length, uint16_t initial)
 * @Description: 模拟CRC16校验函数
 * @Parameters:  data - 数据指针
 *               length - 数据长度
 *               initial - 初始值
 * @Return:      CRC16校验值
 */
uint16_t srv_crc16_system(const uint8_t* data, uint16_t length, uint16_t initial)
{
    if (data == NULL || length == 0)
    {
        return initial;
    }
    
    // 简单的CRC16实现（实际项目中应该使用标准CRC16算法）
    uint16_t crc = initial;
    
    for (uint16_t i = 0; i < length; i++)
    {
        crc ^= data[i];
        for (uint8_t j = 0; j < 8; j++)
        {
            if (crc & 0x0001)
            {
                crc = (crc >> 1) ^ 0xA001;  // CRC16-ANSI多项式
            }
            else
            {
                crc = crc >> 1;
            }
        }
    }
    
    return crc;
}

// =======================================================================================
// End of file.
// =======================================================================================
